package org.zsl.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
import org.zsl.mybatis.model.User;

import java.util.List;

public interface UserMapper {

    @Select("select * from user where user_id=#{userId}")
    @Results(id = "userMapper",value = {
            @Result(column = "user_id",property = "userId"
                    ,jdbcType = JdbcType.INTEGER,id = true),
            @Result(column = "username",property = "username",jdbcType = JdbcType.VARCHAR),
            @Result(column = "role_id",property = "role"
                    ,one = @One(select = "org.zsl.mybatis.mapper.RoleMapper.selectById"
            ,fetchType = FetchType.LAZY))
    })
    User selectById(Integer userId);


    @Select("select * from user")
    @ResultMap(value = "userMapper")
    List<User> selectAll();

}
